package org.dromara.common.sse.config

import org.dromara.common.sse.controller.SseController
import org.dromara.common.sse.core.SseEmitterManager
import org.dromara.common.sse.listener.SseTopicListener
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean

/**
 * SSE 自动装配
 *
 * @author LikeYouDo
 */
@AutoConfiguration
@ConditionalOnProperty(value = ["sse.enabled"], havingValue = "true")
@EnableConfigurationProperties(SseProperties::class)
class SseAutoConfiguration {
    @Bean
    fun sseEmitterManager(): SseEmitterManager {
        return SseEmitterManager()
    }

    @Bean
    fun sseTopicListener(): SseTopicListener {
        return SseTopicListener()
    }

    @Bean
    fun sseController(sseEmitterManager: SseEmitterManager): SseController {
        return SseController(sseEmitterManager)
    }
}
